Private DegreeU As Integer ' Degree in U direction.
Private DegreeV As Integer ' Degree in V direction.
Private MaxU As Integer ' Dimensions of control grid.
Private MaxV As Integer
Private Points() As Point3D ' Control points.
' Holds polylines containing the refined
' grid to display the surface.
Private Polylines As Collection
' u and v increment parameters.
Private GapU As Single
Private GapV As Single
Private Du As Single
Private Dv As Single
' Display flags.
Private ShowControls As Boolean ' Draw control points?
Private ShowGrid As Boolean ' Draw control grid?
' Return the factorial of a number (n!).
Function Factorial(ByVal n As Single) As Single
Dim i As Integer
Dim tot As Single
tot = 1
For i = 2 To n
tot = tot * i
Next i
Factorial = tot
End Function
' Create polylines to represent the surface.
Public Sub InitializeGrid(ByVal degree_u As Integer, ByVal degree_v As Integer, ByVal gap_u As Single, ByVal gap_v As Single, ByVal d_u As Single, ByVal d_v As Single)
Dim u As Single
Dim V As Single
Dim stopu As Single
Dim stopv As Single
Dim X As Single
Dim Y As Single
Dim Z As Single
Dim x1 As Single
Dim y1 As Single
Dim z1 As Single
Dim pline As Polyline3d
DegreeU = degree_u
DegreeV = degree_v
GapU = gap_u
GapV = gap_v
Du = d_u
Dv = d_v
Set Polylines = New Collection
' Create curves with constant u.
stopu = MaxU - DegreeU + 2 + GapU / 10
stopv = MaxV - DegreeV + 2 + Dv / 10
For u = 0 To stopu Step GapU
Set pline = New Polyline3d
Polylines.Add pline
SurfaceValue u, 0, x1, y1, z1
For V = Dv To stopv Step Dv
SurfaceValue u, V, X, Y, Z
pline.AddSegment x1, y1, z1, X, Y, Z
x1 = X
y1 = Y
z1 = Z
Next V
Next u
' Create curves with constant v.
stopv = MaxV - DegreeV + 2 + GapV / 10
stopu = MaxU - DegreeU + 2 + Du / 10
For V = 0 To stopv Step GapV
Set pline = New Polyline3d
Polylines.Add pline
SurfaceValue 0, V, x1, y1, z1
For u = Du To stopu Step Du
SurfaceValue u, V, X, Y, Z
pline.AddSegment x1, y1, z1, X, Y, Z
x1 = X
y1 = Y
z1 = Z
Next u
Next V
End Sub
' Apply a transformation matrix which may not
' contain 0, 0, 0, 1 in the last column to the
' object.
Public Sub ApplyFull(M() As Single)
Dim i As Integer
Dim j As Integer
Dim pline As Polyline3d
' Apply the matrix to the grid if it exists.
If Not Polylines Is Nothing Then
For Each pline In Polylines
pline.ApplyFull M
Next pline
End If
' Apply the matrix to the control points.
For i = 0 To MaxU
For j = 0 To MaxV
m3ApplyFull Points(i, j).coord, M, Points(i, j).trans
Next j
Next i
End Sub
' Draw the transformed object on a PictureBox.
Public Sub Draw(ByVal pic As PictureBox, Optional R As Variant)